/********************************************************************************
 * CategoryOptionsAction.java
 *
 * Created by Jigar Mistry
 * Last modified Date: Sep 8, 2008 4:58:23 PM by Jigar Mistry
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 ********************************************************************************/

package com.printeverywhere.action;

import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ApplicationAware;

import com.opensymphony.xwork2.ValidationAware;
import com.printeverywhere.delegator.CategoryOptionsServiceDelegator;
import com.printeverywhere.dto.CategoryOptions;
import com.printeverywhere.util.AdminConstants;

// TODO: Auto-generated Javadoc
/**
 * The Class CategoryOptionsAction.
 */
public class CategoryOptionsAction  extends AdminSystemSetup implements ValidationAware, ApplicationAware {

	/** Logger for this class. */
	private static final Logger logger = Logger.getLogger(CategoryOptionsAction.class);

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/** The category options. */
	private CategoryOptions categoryOptions;

	private static String homepageSubcategoriesSeparator = AdminConstants.BLANK;


	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	public String execute() throws Exception{
		if (logger.isDebugEnabled()) {
			logger.debug("execute() - start"); //$NON-NLS-1$
		}
		this.categoryOptions = CategoryOptionsServiceDelegator.getCategoryOptions();
		homepageSubcategoriesSeparator = categoryOptions.getHomepageSubcategoriesSeparator();

		if (logger.isDebugEnabled()) {
			logger.debug("execute() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	/**
	 * Update category options.
	 *
	 * @return the string
	 */
	public String updateCategoryOptions() {
		if (logger.isDebugEnabled()) {
			logger.debug("updateCategoryOptions() - start"); //$NON-NLS-1$
		}
		try {
			if (categoryOptions.getHomepageSubcategoriesSeparator().equals(
					AdminConstants.NONE)) {
				categoryOptions
						.setHomepageSubcategoriesSeparator(homepageSubcategoriesSeparator);
			}
			CategoryOptionsServiceDelegator
					.updateCategoryOptions(categoryOptions);
			addActionMessage("Category Options updated successfully.");
		}catch (Exception e) {
			addActionError("Category Options not updated successfully.");
		}
		if (logger.isDebugEnabled()) {
			logger.debug("updateCategoryOptions() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	/**
	 * Gets the category options.
	 *
	 * @return the category options
	 */
	public CategoryOptions getCategoryOptions() {
		return categoryOptions;
	}

	/**
	 * Sets the category options.
	 *
	 * @param categoryOptions the new category options
	 */
	public void setCategoryOptions(CategoryOptions categoryOptions) {
		this.categoryOptions = categoryOptions;
	}

//	@Override
	public void setApplication(Map<String, Object> arg0) {
		// TODO Auto-generated method stub

	}
}